/* Copyright (c) 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package openbang.account.service.entity;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;


/**
 * 存放所有媒体对象。 如：头像、普通图片。
 * 
 * @author aibozeng
 * 
 */

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class MediaObject {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private Long userId;

	/**
	 * GAE Blob服务中的图片的标志键
	 */
	@Persistent
	private String blobKey;

	@Persistent
	private Date creation = new Date();

	@Persistent
	private String contentType;

	@Persistent
	private String fileName;

	/**
	 * 容量 字节
	 */
	@Persistent
	private long size;

	@Persistent
	private String title;

	@Persistent
	private String description;

	@Persistent
	private Long groupId;

	@NotPersistent
	private Group group;
	
	@Persistent
	private boolean isPublic;

	@Persistent
	private Date updTime= new Date();
	
	private static final List<String> IMAGE_TYPES = Arrays.asList("image/png",
			"image/jpeg", "image/tiff", "image/gif", "image/bmp");

	/**
	 * 图片宽度  单位：像素
	 * 注：上传文件时,没有方便的办法得到图片的宽和高. -- 从图片服务器取出再 getHeight()  获取图像的高度。--也不行。
	 */
	@Persistent
	private int width = 0;
	
	/**
	 * 图片高度  单位：像素
	 */
	@Persistent
	private int height = 0;

	public MediaObject() {
	}

	public Long getGroupId() {
		return groupId;
	}

	public void setGroupId(Long groupId) {
		this.groupId = groupId;
	}

	public boolean isPublic() {
		return isPublic;
	}

	public String getDescription() {
		return description;
	}

	public String getTitle() {
		return title;
	}

	public String getFileName() {
		return fileName;
	}

	public long getSize() {
		return size;
	}

	public String getContentType() {
		if (contentType == null) {
			return "text/plain";
		}
		return contentType;
	}

	public boolean isImage() {
		return IMAGE_TYPES.contains(getContentType());
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getBlobKey() {
		return blobKey;
	}

	public void setBlobKey(String blobKey) {
		this.blobKey = blobKey;
	}

	public Date getCreation() {
		return creation;
	}

	public void setCreation(Date creation) {
		this.creation = creation;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public void setFileName(String filename) {
		this.fileName = filename;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setPublic(boolean isPublic) {
		this.isPublic = isPublic;
	}

	public Date getUpdTime() {
		return updTime;
	}

	public void setUpdTime(Date updTime) {
		this.updTime = updTime;
	}

	public Group getGroup() {
		return group;
	}

	public void setGroup(Group group) {
		this.group = group;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}
	
}
